package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.Part;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;
import com.mes.inventory.domain.Warehouse;

/**
 * <p>
 * TaskPart实体，记录任务所利用到的零件需求。
 * </p>
 */
@Entity()
// @org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "T_TASK_PART")
@BatchSize(size = 20)
@Lazy(value = true)
// @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class TaskPart extends BasicModel {

	public final static int REQTYPE_MATERIAL = 0;     // 物料需求
	public final static int REQTYPE_RESOURCE = 1;     // 工装资源需求
	
	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name = "UNIQUE_ID", unique = true)
	private String uniqueId;

	@Column(name = "TASKUID")
	private String taskUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TASKUID", insertable = false, updatable = false)
	protected Task task;

	@Column(name = "PART_NUMBER")
	private String partUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PART_NUMBER", insertable = false, updatable = false)
	protected Part part;

	@Column(name = "QTYREQ")
	private Float reqQty;

	// 获取需求类型描述，0表示物料需求，1表示工装资源需求
	@Column(name = "REQTYPE")
	private Integer reqType;
//	// many-to-one
//	@ForeignKey(name = "null")
//	@ManyToOne(fetch = FetchType.LAZY)
//	@JoinColumnsOrFormulas(value = {
//			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
//			@JoinColumnOrFormula(formula = @JoinFormula(value = "'reqtype'", referencedColumnName = "TYPESNAME")) })
//	protected TypesData reqTypeDesc;

	@Column(name = "ALLOCATEDQTY")
	private Float allocatedQty;

	@Column(name = "ISINEFFECT")
	private Boolean effective;

	@Column(name = "SINGLEIN")
	private Float singleIn;

	@Column(name = "SINGLEOUT")
	private Float singleOut;

	@Column(name = "SATISFYDATE")
	private Date satisfyDate;

	// 预分配数量
	@Column(name = "PREASS_QTY")
	private Float preAssignQty;

	// 预分配者
	@Column(name = "PREASS_EMP")
	private String preAssignEmployeeUid;

	// 预分配时间
	@Column(name = "PREASS_DATE")
	private Date preAssignDate;

	@Column(name = "PREASS_LEVEL")
	private Integer preAssignLevel;
	
	@Column(name = "WAREHOUSEID")
	private String warehouseUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "WAREHOUSEID", insertable = false, updatable = false)
	protected Warehouse warehouse;

	@Column(name = "APPLY_QTY")
	private Float applyQty;

	@Column(name = "PREPARE_EMPLOYEEID")
	private String prepareEmployeeUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PREPARE_EMPLOYEEID", insertable = false, updatable = false)
	protected Employee prepareEmployee;

	@Column(name = "PREPARE_WAREHOUSEID")
	private String prepareWarehouseUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PREPARE_WAREHOUSEID", insertable = false, updatable = false)
	protected Warehouse prepareWarehouse;

	@Column(name = "PREPARE_STATE")
	private Integer prepareState;
//	// many-to-one
//	@ForeignKey(name = "null")
//	@ManyToOne(fetch = FetchType.LAZY)
//	@JoinColumnsOrFormulas(value = {
//			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
//			@JoinColumnOrFormula(formula = @JoinFormula(value = "'preparestate'", referencedColumnName = "TYPESNAME")) })
//	protected TypesData prepareStateDesc;


	/**
	 * 空的构造函数
	 */
	public TaskPart() {
	}

	/**
	 * 获取任务Uid
	 * 
	 * @return
	 */

	public String getTaskUid() {
		return taskUid;
	}

	/**
	 * 设置任务Uid
	 * 
	 * @param taskUid
	 */
	public void setTaskUid(String taskUid) {
		this.taskUid = taskUid;
	}

	/**
	 * 获取任务对象
	 * 
	 * @return
	 */

	public Task getTask() {
		return task;
	}

	/**
	 * 设置任务对象
	 * 
	 * @param task
	 */
	public void setTask(Task task) {
		this.task = task;
	}

	/**
	 * 获取零件编号
	 * 
	 * @return
	 */

	public String getPartUid() {
		return partUid;
	}

	/**
	 * 设置零件编号
	 * 
	 * @param partUid
	 */
	public void setPartUid(String partUid) {
		this.partUid = partUid;
	}

	/**
	 * 获取零件对象
	 * 
	 * @return
	 */

	public Part getPart() {
		return part;
	}

	/**
	 * 设置零件对象
	 * 
	 * @param part
	 */
	public void setPart(Part part) {
		this.part = part;
	}

	/**
	 * 获取需求数量
	 * 
	 * @return
	 */

	public Float getReqQty() {
		return reqQty;
	}

	/**
	 * 设置需求数量
	 * 
	 * @param qtyreq
	 */
	public void setReqQty(Float reqQty) {
		this.reqQty = reqQty;
	}

	/**
	 * 获取需求类型，，0表示物料需求，1表示工装资源需求
	 * 
	 * @return
	 */

	public Integer getReqType() {
		return reqType;
	}

	/**
	 * 设置需求类型，0表示物料需求，1表示工装资源需求
	 * 
	 * @param reqtype
	 */
	public void setReqType(Integer reqType) {
		this.reqType = reqType;
	}

	/**
	 * 获取已领用数量
	 * 
	 * @return
	 */

	public Float getAllocatedQty() {
		return allocatedQty;
	}

	/**
	 * 设置已领用数量
	 * 
	 * @param allocatedqty
	 */
	public void setAllocatedQty(Float allocatedQty) {
		this.allocatedQty = allocatedQty;
	}

	/**
	 * 返回是否有效
	 * 
	 * @return
	 */

	public Boolean getEffective() {
		return effective;
	}

	/**
	 * 设置是否有效
	 * 
	 * @param effective
	 */
	public void setEffective(Boolean effective) {
		this.effective = effective;
	}

	/**
	 * 获取创建者
	 * 
	 * @return
	 */

	public Employee getCreator() {
		return creator;
	}

	/**
	 * 设置创建者
	 * 
	 * @param creator
	 */
	public void setCreator(Employee creator) {
		this.creator = creator;
	}

	/**
	 * 获取单件消耗
	 * 
	 * @return
	 */

	public Float getSingleIn() {
		return singleIn;
	}

	/**
	 * 设置单件消耗
	 * 
	 * @param singleIn
	 */
	public void setSingleIn(Float singleIn) {
		this.singleIn = singleIn;
	}

	/**
	 * 获取单件产出
	 * 
	 * @return
	 */

	public Float getSingleOut() {
		return singleOut;
	}

	/**
	 * 设置单件产出
	 * 
	 * @param singleOut
	 */
	public void setSingleOut(Float singleOut) {
		this.singleOut = singleOut;
	}

	/**
	 * 获取满足日期
	 * 
	 * @return
	 */

	public Date getSatisfyDate() {
		return satisfyDate;
	}

	/**
	 * 设置满足日期
	 * 
	 * @param satisfydate
	 */
	public void setSatisfyDate(Date satisfyDate) {
		this.satisfyDate = satisfyDate;
	}

	/**
	 * 获取库房Uid
	 * 
	 * @return
	 */

	public String getWarehouseUid() {
		return warehouseUid;
	}

	/**
	 * 设置库房Uid
	 * 
	 * @param warehouseUid
	 */
	public void setWarehouseUid(String warehouseUid) {
		this.warehouseUid = warehouseUid;
	}

	/**
	 * 获取库房对象
	 * 
	 * @return
	 */

	public Warehouse getWarehouse() {
		return warehouse;
	}

	/**
	 * 设置库房对象
	 * 
	 * @param warehouse
	 */
	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}

	/**
	 * 获取申请数量
	 * 
	 * @return
	 */

	public Float getApplyQty() {
		return applyQty;
	}

	/**
	 * 设置申请数量
	 * 
	 * @param applyQty
	 */
	public void setApplyQty(Float applyQty) {
		this.applyQty = applyQty;
	}

	/**
	 * 获取准备员Uid
	 * 
	 * @return
	 */

	public String getPrepareEmployeeUid() {
		return prepareEmployeeUid;
	}

	/**
	 * 设置准备员Uid
	 * 
	 * @param prepareemployeeUid
	 */
	public void setPrepareEmployeeUid(String prepareEmployeeUid) {
		this.prepareEmployeeUid = prepareEmployeeUid;
	}

	/**
	 * 获取准备员对象
	 * 
	 * @return
	 */

	public Employee getPreparEemployee() {
		return prepareEmployee;
	}

	/**
	 * 设置准备员对象
	 * 
	 * @param prepareEmployee
	 */
	public void setPreparEemployee(Employee prepareEmployee) {
		this.prepareEmployee = prepareEmployee;
	}

	/**
	 * 获取准备库房Uid
	 * 
	 * @return
	 */

	public String getPrepareWarehouseUid() {
		return prepareWarehouseUid;
	}

	/**
	 * 设置准备库房Uid
	 * 
	 * @param prepareWarehouseUid
	 */
	public void setPrepareWarehouseUid(String prepareWarehouseUid) {
		this.prepareWarehouseUid = prepareWarehouseUid;
	}

	/**
	 * 获取准备库房对象
	 * 
	 * @return
	 */

	public Warehouse getPrepareWarehouse() {
		return prepareWarehouse;
	}

	/**
	 * 设置准备库房对象
	 * 
	 * @param prepareWarehouse
	 */
	public void setPrepareWarehouse(Warehouse prepareWarehouse) {
		this.prepareWarehouse = prepareWarehouse;
	}

	/**
	 * 获取准备状态
	 * 
	 * @return
	 */

	public Integer getPrepareState() {
		return prepareState;
	}

	/**
	 * 设置准备状态
	 * 
	 * @param preparestate
	 */
	public void setPrepareState(Integer prepareState) {
		this.prepareState = prepareState;
	}

	/**
	 * 获取预分配等级
	 * 
	 * @return
	 */

	public Integer getPreAssignLevel() {
		return preAssignLevel;
	}

	/**
	 * 设置预分配等级
	 * 
	 * @param preAssLevel
	 */
	public void setPreAssignLevel(Integer preAssignLevel) {
		this.preAssignLevel = preAssignLevel;
	}

	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getUniqueId();
	}
	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setUniqueId(uuid);
	}

	public Float getPreAssignQty() {
		return preAssignQty;
	}

	public void setPreAssignQty(Float preAssignQty) {
		this.preAssignQty = preAssignQty;
	}

	public String getPreAssignEmployeeUid() {
		return preAssignEmployeeUid;
	}

	public void setPreAssignEmployeeUid(String preAssignEmployeeUid) {
		this.preAssignEmployeeUid = preAssignEmployeeUid;
	}

	public Date getPreAssignDate() {
		return preAssignDate;
	}

	public void setPreAssignDate(Date preAssignDate) {
		this.preAssignDate = preAssignDate;
	}

	public Employee getPrepareEmployee() {
		return prepareEmployee;
	}

	public void setPrepareEmployee(Employee prepareEmployee) {
		this.prepareEmployee = prepareEmployee;
	}
	
}
